'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

Public Class MetaShortUserInformationResponse
    Inherits MetaInformationResponse

    Public Sub New()
        MyBase.New(MetaResponseSubType.ShortUserInformationReply)
    End Sub

    Public Overrides Function CalculateDataSize() As Integer
        Throw New NotImplementedException
    End Function

    Public Overrides Function Serialize() As System.Collections.Generic.List(Of Byte)
        Throw New NotImplementedException
    End Function

    Private _Nickname As String
    Public Property Nickname() As String
        Get
            Return _Nickname
        End Get
        Set(ByVal value As String)
            _Nickname = value
        End Set
    End Property

    Private _FirstName As String
    Public Property FirstName() As String
        Get
            Return _FirstName
        End Get
        Set(ByVal value As String)
            _FirstName = value
        End Set
    End Property

    Private _LastName As String
    Public Property LastName() As String
        Get
            Return _LastName
        End Get
        Set(ByVal value As String)
            _LastName = value
        End Set
    End Property

    Private _EmailAddress As String
    Public Property EmailAddress() As String
        Get
            Return _EmailAddress
        End Get
        Set(ByVal value As String)
            _EmailAddress = value
        End Set
    End Property

    Private _AutorizationRequired As Boolean
    Public Property AuthorizationRequired() As Boolean
        Get
            Return _AutorizationRequired
        End Get
        Set(ByVal value As Boolean)
            _AutorizationRequired = value
        End Set
    End Property

    Private _Gender As Byte
    Public Property Gender() As Byte
        Get
            Return _Gender
        End Get
        Set(ByVal value As Byte)
            _Gender = value
        End Set
    End Property

    Private _SearchSucceeded As Boolean
    Public Property SearchSucceeded() As Boolean
        Get
            Return _SearchSucceeded
        End Get
        Set(ByVal value As Boolean)
            _SearchSucceeded = value
        End Set
    End Property

    Public Overrides Sub Deserialize(ByVal data As System.Collections.Generic.List(Of Byte))
        MyBase.Deserialize(data)

        Dim index As Integer = MetaResponse.SizeFixPart + 2

        If data(index) = &HA Then
            _SearchSucceeded = True
        Else
            _SearchSucceeded = False
            Return
        End If

        index += 1

        _Nickname = ByteConverter.ToZeroBasedStringFromUInt16LEIndex(index, data)
        index += 2 + If(String.IsNullOrEmpty(_Nickname), 0, _Nickname.Length) + 1

        _FirstName = ByteConverter.ToZeroBasedStringFromUInt16LEIndex(index, data)
        index += 2 + If(String.IsNullOrEmpty(_FirstName), 0, _FirstName.Length) + 1

        _LastName = ByteConverter.ToZeroBasedStringFromUInt16LEIndex(index, data)
        index += 2 + If(String.IsNullOrEmpty(_LastName), 0, _LastName.Length) + 1

        _EmailAddress = ByteConverter.ToZeroBasedStringFromUInt16LEIndex(index, data)
        index += 2 + If(String.IsNullOrEmpty(_EmailAddress), 0, _EmailAddress.Length) + 1

        If data(index) = 0 Then _AutorizationRequired = True
        index += 1
        index += 1

        _Gender = data(index)
    End Sub
End Class
